package com.yonyou.pmclouds.basecom.multilanguage;

import com.yonyou.pmclouds.basecom.runtime.RuntimeEnvironment;

import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

public class ResUtil {

	private static volatile ResUtil instance;
	
	private static Map<Language,ResourceBundle> map = new HashMap<Language,ResourceBundle>();
	
	private static byte[] lock=new byte[0];
	
	private ResUtil()
	{

	}
	
	public static ResUtil getInstance(){
        if(instance==null){
            synchronized (lock){
                if(instance==null){
                	instance = new ResUtil();
                	for(Language e : Language.values())
                    {
                    	ResourceBundle res = ResourceBundle.getBundle("Message",e.getValue());
                    	map.put(e, res);
                    }
                }
            }
        }
        return instance;
    }
	
	public String getResString(Language l,String key)
	{
		return map.get(l).getString(key);
	}
	public String[] getResStringArray(Language l,String key)
	{
		return map.get(l).getStringArray(key);
	}
	
	public String getResString(String key)
	{
		return map.get(RuntimeEnvironment.getLanguage()).getString(key);
	}
	public String[] getResStringArray(String key)
	{
		return map.get(RuntimeEnvironment.getLanguage()).getStringArray(key);
	}
}
